package itheima.com.socketdemo77;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
    public static void main(String[] args) throws IOException {
        //创建客户端对象接收数据
        ServerSocket ss = new ServerSocket(8888);
        //先从客户端接收数据
        Socket accept = ss.accept();
        //调用输入流方法将数据准备读取
        InputStream is = accept.getInputStream();
        int b;
        while ((b=is.read())!=-1){
            System.out.print((char) b);
        }

        //用转换流进行数据转化成字符流，方便读取数据
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(accept.getOutputStream()));
        bw.write("你不要过来啊");
        bw.newLine();
        bw.flush();

        is.close();
        accept.close();
        bw.close();
        ss.close();

    }
}
